package org.example.code.test2025.two_month;

import java.util.Scanner;

public class test0228 {
    private static int max = 0;
    private static int m;
    private static int n;
    private static int[] a;
    private static int[] b;
    private static int[] c;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        m = in.nextInt();
        a = new int[n];
        for(int i=0;i<n;i++){
            a[i] = in.nextInt();
        }
        b = new int[m];
        c = new int[m];
        for(int i=0;i<m;i++){
            b[i]=in.nextInt();
            c[i]=in.nextInt();
        }
        int[] state = new int[n];
        fun2(0,state,0);
        System.out.println(max);
    }

    private static void fun2(int index,int[] state,int cur){
       if(index == m){
           max = Math.max(max,cur);
           return;
       }
       for(int i=0;i<n;i++){
           if(state[i]==0&&a[i]>=b[index]){
               state[i]=1;
               fun2(index+1,state,cur+c[index]);
               state[i]=0;
           }
       }
       fun2(index+1,state,cur);
    }

    private static void fun(int count){
        StringBuilder sb = new StringBuilder();
        while(count>0){
            int t = count%10;
            if(t%2==0){
                sb.insert(0,'0');
            }else{
                sb.insert(0,'1');
            }
            count=count/10;
        }
        if(sb.length()==0){
            sb.append('0');
        }
        System.out.println(Integer.parseInt(sb.toString()));
    }
}
